package com.itehima.Exception1;

public class GrirlFRINED {
    private String name;
    private int age;

    public GrirlFRINED() {
    }

    public GrirlFRINED(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void setName(String name) {
       //要求姓名的长度是3-10之间
        int len=name.length();
        if(len<3||len>10)
            throw new NameFormatException(name+"格式有误");


        this.name = name;
    }

    public void setAge(int age) {
        //要求年龄范围要在18-40
        if(age<18||age>40)
            throw new AgeOutofBoundsException(age+"超出范围");

        this.age = age;
    }
    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }




    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }




    public String toString() {
        return "GrirlFRINED{name = " + name + ", age = " + age + "}";
    }
}
